package org.springblogs.init;

import java.sql.Timestamp;
import java.util.List;

import org.springblogs.dao.StockMarketRepository;
import org.springblogs.model.StockMarket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

@Order(10)
//@Component
public class InitStockMarket implements CommandLineRunner {
	@Autowired
	private StockMarketRepository repository;
	@Override
	public void run(String... args) throws Exception {
		List<StockMarket> markets = repository.findAll();
		System.out.println(String.format("this are %s markets", markets.size()));
		if(CollectionUtils.isEmpty(markets)) {
			StockMarket sz = new StockMarket();
			sz.setMarket("sz");
			sz.setName("深圳股票");
			sz.setUpdatedDate(new Timestamp(System.currentTimeMillis()));
			repository.save(sz);
			
			StockMarket sh = new StockMarket();
			sh.setMarket("sh");
			sh.setName("上海股票");
			sh.setUpdatedDate(new Timestamp(System.currentTimeMillis()));
			repository.save(sh);
		}

	}

}
